﻿namespace M3uPlaylist
{
    using PlaylistCopy.Contract;
    using System.Collections.Generic;
    using System.ComponentModel.Composition;
    using System.IO;

    [Export(typeof(IPlaylist))]
// ReSharper disable once InconsistentNaming
    public class M3uPlaylistImpl : IPlaylist
    {
        public string PlaylistExtension
        {
            get { return "m3u"; }
        }

        public IEnumerable<string> GetMusicFiles(Stream stream)
        {
            using (var streamReader = new StreamReader(stream))
            {
                string line;
                while ((line = streamReader.ReadLine()) != null)
                {
                    var lowered = line.ToLowerInvariant();
                    if (lowered.StartsWith("#") || lowered.StartsWith(" "))
                    {
                        continue;
                    }

                    yield return line;
                }
            }
        }
    }
}
